/*
 * Powered By dico
 * Since 2017 - 2018
 */package com.seeyoui.kensite.bussiness.orderlang.productPrice.service;
 
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.seeyoui.kensite.bussiness.orderlang.productPrice.domain.ProductPrice;
import com.seeyoui.kensite.bussiness.orderlang.productPrice.domain.ProductPriceSpecDTO;
import com.seeyoui.kensite.bussiness.orderlang.productPrice.persistence.ProductPriceMapper;
import com.seeyoui.kensite.common.base.service.BaseService;
import com.seeyoui.kensite.common.exception.CRUDException;

/**
 * ProductPrice
 * @author dico
 * @version 2.0
 * @since 1.0
 * @date 2018-02-07
 */

@Service
public class ProductPriceService extends BaseService {
	
	@Autowired
	private ProductPriceMapper productPriceMapper;
	
	public ProductPrice findOneByProductId(String productId){
		return productPriceMapper.findOneByProductId(productId);
	}
	
	public List<ProductPrice> findIdsByProductId(String productId){
		return productPriceMapper.findIdsByProductId(productId);
	}
	
	public List<ProductPriceSpecDTO> findPriceByProductId(String productId){
		return productPriceMapper.findPriceByProductId(productId);
	}
	
	public String findMaxPriceByProductId(String productId){
		return productPriceMapper.findMaxPriceByProductId(productId);
	}
	
	public String findMinPriceByProductId(String productId){
		return productPriceMapper.findMinPriceByProductId(productId);
	}
	
	public String findDiscountPriceByUserLevel(String type,String priceId){
		Map<Object, Object> map = new HashMap<Object, Object>();
		map.put("level", type);
		map.put("priceId", priceId);
		return productPriceMapper.findDiscountPriceByUserLevel(map);
	}

	/**
	 * 根据ID查询单条数据
	 * @param id
	 * @return
	 * @throws CRUDException
	 */
	public ProductPrice findOne(String id) throws CRUDException{
		return productPriceMapper.findOne(id);
	}
	
	/**
	 * 查询数据集合
	 * @param productPrice
	 * @return
	 * @throws CRUDException
	 */
	public List<ProductPrice> findList(ProductPrice productPrice) throws CRUDException {
		return productPriceMapper.findList(productPrice);
	}
	
	/**
	 * 查询所有数据集合
	 * @param productPrice
	 * @return
	 * @throws CRUDException
	 */
	public List<ProductPrice> findAll(ProductPrice productPrice) throws CRUDException {
		return productPriceMapper.findAll(productPrice);
	}
	
	/**
	 * 查询数据总数
	 * @param productPrice
	 * @return
	 * @throws CRUDException
	 */
	public int findTotal(ProductPrice productPrice) throws CRUDException {
		return productPriceMapper.findTotal(productPrice);
	}
	
	/**
	 * 查询数据总数排除当前数据
	 * @param productPrice
	 * @return
	 * @throws CRUDException
	 */
	public int findExTotal(ProductPrice productPrice) throws CRUDException {
		return productPriceMapper.findExTotal(productPrice);
	}
	
	/**
	 * 数据新增
	 * @param productPrice
	 * @throws CRUDException
	 */
	public void save(ProductPrice productPrice) throws CRUDException{
		productPrice.preInsert();
		productPriceMapper.save(productPrice);
	}
	
	/**
	 * 数据修改
	 * @param productPrice
	 * @throws CRUDException
	 */
	public void update(ProductPrice productPrice) throws CRUDException{
		productPrice.preUpdate();
		productPriceMapper.update(productPrice);			
	}
	
	/**
	 * 数据删除
	 * @param listId
	 * @throws CRUDException
	 */
	public void delete(List<String> listId) throws CRUDException {
		productPriceMapper.delete(listId);
	}
	
	public void deleteByProductId(String productId){
		productPriceMapper.deleteByProductId(productId);
	}
	
	/**
	 * 数据假删除
	 * @param productPrice
	 * @throws CRUDException
	 */
	public void remove(ProductPrice productPrice) throws CRUDException{
		productPrice.preUpdate();
		productPriceMapper.remove(productPrice);			
	}
	
}